<template>
  <div class="list-table">
    <div v-if="showTopTitle" class="area-header">
      <span class="area-header-title">{{ $t('出资人操作日志') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('出资人')" prop="lpId">
        <MainBodySelect
          v-model="queryParams.lpId"
          :show-label="false"
          parameters="lpInvestor"
        />
      </el-form-item>
      <el-form-item :label="$t('基金名称')" prop="fundId">
        <el-select v-model="queryParams.fundId" clearable filterable :placeholder="$t('基金名称')" @keyup.enter.native="queryHandle">
          <el-option
            v-for="dict in fundOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('访问界面')" prop="operationType">
        <el-select v-model="queryParams.operationType" clearable filterable :placeholder="$t('访问界面')" @keyup.enter.native="queryHandle">
          <el-option
            v-for="dict in selectPageOption"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <!--<el-form-item :label="$t('动作')" prop="actionMain">-->
      <!--  <el-input-->
      <!--    v-model="queryParams.actionMain"-->
      <!--    :placeholder="$t('动作')"-->
      <!--    clearable-->
      <!--    @keyup.enter.native="queryHandle"-->
      <!--  />-->
      <!--</el-form-item>-->
      <el-form-item :label="$t('操作时间')">
        <DatePicker
          v-model="dateRange"
          type="daterange"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
        <!--<el-button v-hasPermi="['lpPortal:operationLog:export']" type="warning" icon="el-icon-download" size="mini" @click="exportHandle">{{ $t('导出') }}</el-button>-->
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="lpOperationLogList" border tooltip-effect="darkTable">
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('出资人')" align="center" prop="lpName" show-overflow-tooltip min-width="180" />
      <el-table-column :label="$t('基金名称')" align="center" prop="fundName" show-overflow-tooltip min-width="180" />
      <el-table-column :label="$t('操作时间')" align="center" prop="operationTime" show-overflow-tooltip min-width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.operationTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('访问界面')" align="center" prop="operationType" show-overflow-tooltip min-width="130" />
      <el-table-column :label="$t('动作')" align="left" prop="actionMain" show-overflow-tooltip min-width="200">
        <template slot-scope="scope">
          {{ scope.row.actionMain }} {{ scope.row.actionSub }}
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { listLpOperationLogAll, exportLpOperationLog, selectPage, selectFund } from '@/api/fund/lpBase/lp/lpOperationLog/lpOperationLog.js'
import MainBodySelect from '@/components/MainBodySelect'
export default {
  components: {
    MainBodySelect
  },
  props: {
    showTopTitle: {
      type: Boolean,
      default: () => true
    }
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 总条数
      total: 0,
      // LP门户操作记录表格数据
      lpOperationLogList: [],
      // 弹出层标题
      title: '出资人操作日志',
      // 查询参数
      queryParams: {
        lpId: undefined,
        fundId: undefined,
        operationType: undefined,
        operationTime: undefined,
        actionMain: undefined,
        actionSub: undefined,
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      // 动作界面下拉
      selectPageOption: [],
      // 基金搜索下拉
      fundOptions: [],
      // 时间区间
      dateRange: []
    }
  },
  watch: {
  },
  created() {
    this.getList()
    selectPage().then(response => {
      this.selectPageOption = []
      if (response.data) {
        response.data.forEach(item => {
          this.selectPageOption.push({ dictLabel: item, dictValue: item })
        })
      }
    })
    selectFund().then(response => {
      this.fundOptions = response.data
    })
  },
  mounted() {
  },
  methods: {
    /** 查询LP门户操作记录列表 */
    getList() {
      this.loading = true
      listLpOperationLogAll(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.lpOperationLogList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        lpId: undefined,
        operationType: undefined,
        operationTime: undefined,
        actionMain: undefined,
        actionSub: undefined,
        delFlag: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.resetForm('queryForm')
      this.queryHandle()
    },
    /** 导出按钮操作 */
    exportHandle() {
      const queryParams = this.queryParams
      this.$confirm(this.$t('是否确认导出数据项?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      }).then(() => {
        return exportLpOperationLog(queryParams)
      }).then(response => {
        this.download(response.msg)
      }).catch(() => {
        this.loading = false
      })
    }
  }
}
</script>
